package top.hcode.hoj.service.oj.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.mapper.DepMapper;
import top.hcode.hoj.pojo.entity.user.Dep;
import top.hcode.hoj.service.oj.DepService;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

@Service
@Resource
public class DepServiceImpl implements DepService {
    @Autowired
    private DepMapper depMapper;



    @Override
    public CommonResult<List<Dep>> getdeplists(String oj) {
        return   CommonResult.successResponse(depMapper.getdeplists(oj));
    }

    @Override
    public boolean adddep(Dep dep) {
        String uuid = ThreadLocalRandom.current()
                .ints(20, 0, 10)  // 生成 20 个 0-9 的随机数字
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
                .toString();
        dep.setId(uuid);

            boolean affected = depMapper.adddep(dep);
            return affected;

    }

    @Override
    public CommonResult<Void> updatedep(Dep dep) {
            depMapper.updatedep(dep);
            return CommonResult.successResponse();

    }

    @Override
    public int deletedep(String depid) {
        return depMapper.deleteById(depid);
    }
}
